package com.sfx.concurrent.demo.concurrent.MyThreadPool2;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2023-03-24
 * Time: 15:22
 */
@Slf4j(topic = "c.TestMain")
public class TestMain {
    public static void main(String[] args) {
        MyThreadPool myThreadPool = new MyThreadPool
        (1,1000, TimeUnit.MILLISECONDS,1,
                (queue,task)->{
                    //1.队列满了就死等
                    //queue.put(task);
                    //2.放弃任务的执行
                    //什么都不做
                    //log.debug("放弃任务...");
                    //3.抛出异常
                    //throw new RuntimeException("任务执行失败");
                    //4.调用者自己去执行任务
                    task.run();
                    //5.带超时的等待
                    //queue.offer(task,500,TimeUnit.MILLISECONDS);
                });
        /**
         * 核心线程很忙并且任务队列又满了,会发生什么 ?
         * 答案是 会阻塞住
         */
        for(int i =0;i<4;++i) {
            int j = i;
            myThreadPool.execute(()->{
                try {
                    Thread.sleep(1000L);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                log.debug("{}",j);
            });
        }
    }
}